var api = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        current_page: 1,
        column: '',
        u_id: '',
        userArticleList: [],
        upLog: true
    },

    toFnas: function () {
        wx.navigateTo({
            url: "../me-fans/me-fans?u_id=" + this.data.u_id
        });
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        var a = this, u_id = wx.getStorageSync('userData').u_id, page = a.data.current_page;
        a.data.u_id = u_id;
        a.mineLoad(u_id, u_id);
        a.userArticleList(u_id, page);
    },
    mineLoad: function (u_id, follow_id) {
        var a = this;
        wx.showLoading({
            title: "加载中"
        });
        wx.request({
            url: api.globalData.Api + '/userInfo',
            method: 'GET',
            data: {
                u_id: u_id,
                follow_id: follow_id
            },
            success: function(res) {
                if (res.data.status == 1) {
                    a.setData({
                        userData: res.data.data
                    });
                }
            }
        });
    },
    userArticleList: function (u_id, page){
        var a = this;
        wx.showLoading({
            title: "加载中"
        });
        wx.request({
            url: api.globalData.Api + '/userArticleList',
            method: 'GET',
            data: {
                u_id: u_id,
                page: page
            },
            success: function (res) {
                if (res.data.status == 1) {
                    a.data.userArticleList = res.data.data.data;
                    a.setData({
                        userArticleList: res.data.data.data,
                        upLog: true
                    }), wx.hideLoading(), wx.stopPullDownRefresh();
                }
            }
        });
    },
    clickArticle: function(o) {
        var a_id = o.currentTarget.dataset.a_id,
            u = wx.getStorageSync('userData');
        wx.navigateTo({
            url: './mine-article?article_id=' + a_id + '&user_id=' + u.u_id
        })
    },
    goCzuo: function(){
        wx.switchTab({
            url: '../post/post',
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
        
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {
        var u = this.data.u_id;
        this.userArticleList(u, 1);
        this.mineLoad(u, u);
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {
        var a = this, page = parseInt(a.data.current_page) + 1;
        var u_id = a.data.u_id;
        if (a.data.upLog){
            wx.showLoading({
                title: "加载中"
            });
            wx.request({
                url: api.globalData.Api + '/userArticleList',
                method: 'GET',
                data: {
                    u_id: u_id,
                    page: page
                },
                success: function (res) {
                    var e = res.data.data.data, j = a.data.userArticleList;
                    if (e.length == 0) {
                        wx.showToast({
                            title: '已全部加载完成！',
                            duration: 1000,
                        });
                        a.setData({
                            upLog: false
                        });
                    } else {
                        // concat 合并数组
                        that.setData({
                            userArticleList: j.concat(e),
                            current_page: page
                        }), wx.hideLoading();
                    }
                }
            })
        }
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    }
})